import {GET_IMAGE_LIST,GET_CATEGORY,CHANGE_SWIPER,INIT_CATEGORY,CHANGE_INDEX} from '../actionTypes';
export default (state={
    imageList:[],
    categoryList:[],  //当前分类图片列表
    Count:0,          //当前分类的图片总数量
    swiperOpen:false,  //控制swiper弹窗显示隐藏
    activeIndex:-1    //当前swiper展示的图片索引
},action) => {
    switch (action.type) {
        case GET_IMAGE_LIST:{
            let {list} = action;
            return {
                ...state,
                imageList:[...list]
            }
        }
        //获取对应分类的图片列表
        case GET_CATEGORY:{
            let {data} = action;
            console.log("state.categoryList",state.categoryList.length);
            return {
                ...state,
                categoryList:[...state.categoryList,...data.List],  //对应分类的图片列表
                Count:data.Count              //总条数
            }
        }

        //初始化分类的图片列表
        case INIT_CATEGORY:{
            return {
                ...state,
                categoryList:[]
            }
        }

        //修改swiper弹窗显示隐藏
        case CHANGE_SWIPER:{
            let {isOpen} = action;
            return {
                ...state,
                swiperOpen:isOpen
            }
        }
        //修改activeIndex
        case CHANGE_INDEX:{
            let {index} = action;
            return {
                ...state,
                activeIndex:index
            }
        }
        //弹窗
        default:{
            return state
        }
    }
}